using UnityEngine;

namespace CinemaDirector
{
	[ExecuteInEditMode]
	public class CinemaAudio : TimelineActionFixed
	{
		private bool wasPlaying;

		public void Trigger()
		{
		}

		public void End()
		{
			Stop();
		}

		public void UpdateTime(float time, float deltaTime)
		{
			AudioSource component = base.gameObject.GetComponent<AudioSource>();
			if (component != null)
			{
				component.mute = false;
				if (base.Cutscene.State == Cutscene.CutsceneState.Scrubbing)
				{
					component.time = time + base.InTime;
				}
				if (!component.isPlaying)
				{
					component.time = time + base.InTime;
					component.Play();
				}
			}
		}

		public void Resume()
		{
			AudioSource component = base.gameObject.GetComponent<AudioSource>();
			if (component != null && wasPlaying)
			{
				component.Play();
			}
		}

		public void Pause()
		{
			AudioSource component = base.gameObject.GetComponent<AudioSource>();
			if (component != null)
			{
				wasPlaying = false;
				if (component.isPlaying)
				{
					wasPlaying = true;
				}
				component.Pause();
			}
		}

		public override void Stop()
		{
			AudioSource component = base.gameObject.GetComponent<AudioSource>();
			if ((bool)component)
			{
				component.Stop();
			}
		}

		public void SetTime(float audioTime)
		{
			AudioSource component = base.gameObject.GetComponent<AudioSource>();
			if (component != null)
			{
				component.time = audioTime;
			}
		}
	}
}
